package com.mh.service.impl;

import com.mh.dto.R;
import com.mh.pojo.StoreInfos;
import com.mh.service.StoreInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

/**
 * Date:2024/10/22
 * author:zmh
 * description: 店铺服务实现类
 **/

@Service
@Slf4j
@RequiredArgsConstructor
public class StoreInfoServiceImpl implements StoreInfoService {

    private final MongoTemplate mongoTemplate;

    /**
     * 根据店铺ID查询店铺信息
     * @param storeId 店铺ID
     * @return ·
     */
    @Override
    public R<StoreInfos> getStoreInfoById(String storeId) {
        Query query = new Query().addCriteria(Criteria.where("storeId").is(storeId));
        StoreInfos storeInfos = mongoTemplate.findOne(query, StoreInfos.class);
        if(storeInfos == null){
            return R.error("店铺不存在");
        }
        return R.success(storeInfos);
    }
}
